Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #18152: Cast should be disabled on toggling off media router switch in extension settings #10116

Merged
merged 1 commit into from
Oct 3, 2021

Conversation

jumde
Copy link
Contributor

@jumde jumde commented Sep 16, 2021

Resolves brave/brave-browser#18152

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Desktop

  1. Enable network filter for little snitch
  2. Using a new profile, open Brave Browser
  3. Navigate to brave://settings/extensions and verify that cast media router is not enabled by default
  4. Verify that SSDP requests are not sent by default
  5. Navigate to brave://settings/extensions and toggle cast switch
  6. Restart button should be visible
  7. Redirect to brave://flags and navigate back to brave://settings/extensions. Verify the restart button is still visible
  8. Restart browser
  9. Verify cast works
  10. Navigate to brave://settings/extensions - Disable cast - Restart
  11. Verify the cast no longer works.

Android

  1. Verify that cast works on android by default

@jumde jumde requested a review from a team as a code owner September 16, 2021 04:31
Copy link
Contributor

@mariospr mariospr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@SergeyZhukovsky SergeyZhukovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@jumde jumde requested a review from a team as a code owner September 17, 2021 18:44
@jumde jumde force-pushed the cast_disable branch 2 times, most recently from 05b9008 to 39409da Compare September 17, 2021 20:19
@@ -409,6 +409,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {

registry->SetDefaultPrefValue(prefs::kEnableMediaRouter, base::Value(false));

registry->RegisterBooleanPref(kBraveMediaRouter, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we're adding a new pref and how is this different from prefs::kEnableMediaRouter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast extension requires a browser restart once the setting is toggled. We use the pref kBraveMediaRouter as a proxy to identify the current state of the switch and prefs::kEnableMediaRouter is updated to kBraveMediaRouter on browser start.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we already had something like this?

@@ -92,6 +92,7 @@ extern const char kSafetynetStatus[];
extern const char kDefaultBrowserLaunchingCount[];
extern const char kTabsSearchShow[];
extern const char kDontAskForCrashReporting[];
extern const char kBraveMediaRouter[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above these prefs need comments explaining them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -5,6 +5,7 @@

#include "chrome/browser/media/router/media_router_feature.h"

#include "brave/common/pref_names.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't appear to be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


KeyedService* MediaRouterUIServiceFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
#if !defined(OS_ANDROID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs a comment because I don't understand why we're doing this or why it's happening here because this definitely doesn't seem like the right place. If kEnableMediaRouter needs to be kept in sync with kBraveMediaRouter, there should be a pref observer for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// kBraveMediaRouter is used as a proxy to identify the current state of the
// switch and prefs::kEnableMediaRouter is updated to kBraveMediaRouter
// on restart.
const char kBraveMediaRouter[] = "brave.media_router";
Copy link
Collaborator

@bridiver bridiver Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this naming is confusing imo. It makes it sound like we have our own media router. If this pref is needed (not sure why we can't just restart when changing kEnableMediaRouter) it should be renamed to something like kEnableMediaRouterOnRestart

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the comment should go in the .h file, not the .cc file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved


KeyedService* MediaRouterUIServiceFactory::BuildServiceInstanceFor(
BrowserContext* context) const {
// Chromecast is enabled by default on Android.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go in BraveProfileManager::InitProfileUserPrefs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@@ -366,11 +368,15 @@ void BraveAddAboutStrings(content::WebUIDataSource* html_source,
html_source->AddString("aboutProductLicense", license);
}

void BraveAddSocialBlockingLoadTimeData(content::WebUIDataSource* html_source,
Profile* profile) {
void BraveAddExtensionSettingsLoadTimeData(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old name didn't make sense, but neither does this one and I don't think this needs to be a method anyway, just put them directly in BraveAddLocalizedStrings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved!

// on restart
#if !defined(OS_ANDROID)
auto* pref_service = profile->GetPrefs();
auto enabled = pref_service->GetBoolean(kEnableMediaRouterOnRestart);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to check IsDefaultValue or this will disable for everyone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved!

@jumde jumde force-pushed the cast_disable branch 8 times, most recently from 32bcea1 to 92b0031 Compare September 29, 2021 00:40
@jumde jumde requested a review from bridiver September 29, 2021 02:07
@@ -101,6 +101,13 @@ const char kMRUCyclingEnabled[] = "brave.mru_cycling_enabled";
const char kTabsSearchShow[] = "brave.tabs_search_show";
const char kDontAskForCrashReporting[] = "brave.dont_ask_for_crash_reporting";

// Cast extension requires a browser restart once the setting is toggled.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment should be in the .h file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

"signInAllowedOnNextStartupInitialValue",
profile->GetPrefs()->GetBoolean(prefs::kSigninAllowedOnNextStartup));

html_source->AddBoolean("mediaRouterEnabledInitialValue",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ts/js naming convention should match c++ to avoid confusion. isMediaRouterEnabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -21,6 +21,7 @@ cr.define('settings', function () {
isWidevineEnabled() {}
getRestartNeeded () {}
wasSignInEnabledAtStartup () {}
wasMediaRouterEnabledAtStartup () {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the pref isMediaRouterEnabled fully captures what this value is and is consistent with c++

@jumde jumde merged commit 11701aa into master Oct 3, 2021
@jumde jumde deleted the cast_disable branch October 3, 2021 22:34
@jumde jumde added this to the 1.32.x - Nightly milestone Oct 3, 2021
jumde added a commit that referenced this pull request Oct 4, 2021
Fix #18152: Cast should be disabled on toggling off media router switch in extension settings
@kjozwiak
Copy link
Member

kjozwiak commented Oct 8, 2021

Verification PASSED on Win 11 x64 using the following build:

Brave | 1.32.56 Chromium: 95.0.4638.40 (Official Build) nightly (64-bit)
-- | --
Revision | e3e7c76ba0284b16087cf4cf3153abfaef6470c7-refs/branch-heads/4638@{#624}
OS | Windows 11 Version 21H2 (Build 22000.194)
  • ensured that Media Router is disabled by default via brave://settings/extensions
  • ensured that there's no SSDP packets being sent while Media Router is disabled
Disabled Enabled
nossdpPackets ssdpPackets

castEnabled

  • ensured that there's a Relaunch button once Media Router has been enabled
  • ensured that switching between brave://settings/extensions & brave://flags doesn't remove the Relaunch button

restartButton

  • ensured that Cast... appears under the Hamburger Menu when Media Router is enabled
  • ensured that Cast.... is removed under the Hamburger Menu when Media Router has been disabled
  • ensured that you cannot cast nor see any SSDP packets after disabling Media Router via brave://settings/extensions

Casting Tab/YouTube

Example Example
castingYouTube 20211008_032938

Casting Desktop

Example Example
castingDesktop 20211008_033334

Casting Local File

Example Example
castingFile 20211008_033650

Verification PASSED on Samsung S10+ running Android 11 using the following build:

Brave | 1.32.56 Chromium: 95.0.4638.40
  • ensured that Media Router was enabled by default by visiting https://gem.cbc.ca/live/channel/ottawa and ensuring that the Cast icon was being displayed via the media player
  • ensured that tapping on the Cast button displayed a modal with all the devices that can cast
Example Example Example Example
Screenshot_20211008-034947_Brave - Nightly 20211008_035050 20211008_035325 Screenshot_20211008-035245_Brave - Nightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast is not disabled on toggling off media router switch in extension settings
5 participants